
#include <iostream>
using namespace std;
class Person
{
public:
    Person() {}
    virtual ~Person() {}
    // virtual void work() { cout << "Person::work()\n"; }
    virtual void work() = 0;
};

class Student : public Person
{
public:
    Student() {}
    ~Student() {}
    virtual void work() { cout << "Student::work()\n"; }
    void study() { cout << "Student::study()\n"; }
};

class Teacher : public Person
{
public:
    Teacher() {}
    ~Teacher() {}
    virtual void work()  { cout << "Teacher::work()\n"; }
    void teach()  { cout << "Teacher::teach()\n"; }
};

void doSomething(Person *p)
{
    p->work();
    if(typeid(*p) == typeid(Student)) {
        Student *stu = dynamic_cast<Student*>(p);
        stu->study();
    }
    if(typeid(*p) == typeid(Teacher)) {
        Teacher *tea = dynamic_cast<Teacher*>(p);
        tea->teach();
    }
}

int main()
{
    cout << "sizeof(Person) = " << sizeof(Person) << endl;
    // Person *per = new Person;
    Person *stu = new Student;
    Person *tea = new Teacher;
    doSomething(stu);
    doSomething(tea);
    // per->work();
    // stu->work();
    // tea->work();
    // delete per;
    // per = nullptr;
    delete stu;
    stu = nullptr;
    delete tea;
    tea = nullptr;
    return 0;
}